<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateGroupMembersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('group_members', function (Blueprint $table) {
            $table->unsignedBigInteger('id')->primary();
            $table->unsignedBigInteger('user_id')->default(0)->comment('成员userID!')->index('user');
            $table->string('phone',255)->default('')->comment('联系电话');
            $table->string('name',255)->default('')->comment('联系人');
            $table->string('province',255)->nullable()->comment('省');
            $table->string('city',255)->nullable()->comment('市');
            $table->string('area',255)->nullable()->comment('区');
            $table->string('avatar_url',255)->nullable()->default('')->comment('头像');
            $table->string('address',255)->nullable()->default('')->comment('地址');
            $table->string('address_detail',255)->default('')->comment('详细地址');
            $table->unsignedBigInteger('group_id')->default(0)->comment('成员所在设备分组')->index('group');
            $table->enum('role',['DISTRIBUTOR','MERCHANT','STAFF'])->default('DISTRIBUTOR')->comment('成员群组角色');
            $table->unsignedBigInteger('policy_rule_id')->nullable()->default(0)->comment('成员分成策略id 默认为0的情况下 分成20% 有的话则分开计算平均');
            $table->timestamps();
            $table->softDeletes();
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
            $table->engine = 'InnoDB';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('group_members');
    }
}
